// Copyright DustedPixels.com 2008. All rights reserved.

package kroff.opt;

/**
 * After injecting incrementor
 */
public final class TopLevel3 {

  private final Runnable thousandToOne_onceInThousand;
  private int thousandToOne_counter = 0;
  
  private final Counter incrementor_counter;  
  
  public TopLevel3(Runnable external) {
    this.incrementor_counter = new Counter();
    this.thousandToOne_onceInThousand = external;
  }
  
  public void run() {
    thousandToOne_run();
  }

  private void thousandToOne_run() {
    incrementor_run();
    if (thousandToOne_counter == 0) {
      thousandToOne_onceInThousand.run();
    }
    thousandToOne_counter = (thousandToOne_counter + 1) % 1000;
  }

  private void incrementor_run() {
    incrementor_counter.inc();
  }

  

}
